package org.bizming.web.action;

import java.util.List;

import org.bizming.medicine.model.Medicine;
import org.bizming.medicine.service.RemainService;
import org.bizming.web.util.Helper;
import org.bizming.web.util.WebUtil;

public class RemainAction {

	private RemainService remainService;

	public int count() {
		return remainService.count();
	}

	/**
	 * 查看所有还有货的医药
	 * 
	 * @return
	 */
	public String selectList() {
		List<Medicine> list = remainService.selectList();
		WebUtil.getRequest().setAttribute("list", list);
		return "selectList";
	}

	public String query() {
		String query = WebUtil.getRequest().getParameter("query");
		List<Medicine> list = null;
		if (!Helper.isEmpty(query)) {
			list = remainService.query(query);
		}
		// JSONObject jsonObject = new JSONObject();
		// jsonObject.put("data", list);
		// WebUtil.outputJSONResult(jsonObject, WebUtil.getResponse());
		WebUtil.getRequest().setAttribute("list", list);

		return "query";
	}

	public String shipmentPage() {
		String medicineid = WebUtil.getRequest().getParameter("medicineid");
		int id = Integer.valueOf(medicineid);
		Medicine medicine = remainService.get(id);
		WebUtil.getRequest().setAttribute("t", medicine);

		return "shipment";
	}

	public RemainService getRemainService() {
		return remainService;
	}

	public void setRemainService(RemainService remainService) {
		this.remainService = remainService;
	}
}
